Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
Not adding to the map, Staying the same name "t-1"

I'm making it so if a member says ~new, it makes a new ticket for him, but the problem is, the channel name has to go in a unique number, like t-1 then t-2 ect...

But it's sticking with "t-1" only, to be clear, I'm using a command handler.

here is my code:

module.exports = {
  name: 'new',
  category: 'Ticket',
  description: 'Creates a new ticket.',
  aliases: ['newticket'],
  usage: 'new',
  userperms: [],
  botperms: [],
  run: async (client, message, args) => {

  let ticketCounter = 1;
  const userTickets = new Map()

        if(userTickets.has(message.author.tag)) {
            return message.channel.send('<@' + message.author.id + '> you already have a ticket, please close your existing ticket first before opening a new one!').then(m => m.delete({timeout: 3000}));
        }
        
        message.guild.channels.create(`t-${ticketCounter}`, {
            permissionOverwrites: [
                {
                    id: message.author.id,
                    allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                },
                {
                    id: "916785912267034674",
                    allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                },
                {
                    id: message.guild.roles.everyone,
                    deny: ['VIEW_CHANNEL'],
                },
            ],
            type: 'text',
        }).then(async channel => {
            channel.setParent('916778691672031293');
            userTickets.set(message.author.id, ticketCounter++);
            message.channel.send(`<@` + message.author.id + `>, you have successfully created a ticket! Please click on ${channel} to view your ticket.`).then(m => m.delete({timeout: 3000}));
            channel.send(`Hi <@` + message.author.id + `>, welcome to your ticket! Please be patient, we will be with you shortly.`);
            
            const logchannel = message.guild.channels.cache.find(channel => channel.name === 'test');
            
            if(logchannel) {
                logchannel.send(`Ticket-${ticketCounter} created. Click the following to veiw <#${channel.id}>`);
            }
        });
    }
}

Thanks!

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Use <Map>.size instead of an incrementer since the code is reexecuted after each command, the counter will be set to 1 each time.

if(!client.userTickets) client.userTickets = new Map();
client.userTickets.set(message.author.id, client.userTickets.size + 1);
message.guild.channels.create(`t-${client.userTickets.size + 1}`, { ... });

Example for your code:

module.exports = {
  name: 'new',
  category: 'Ticket',
  description: 'Creates a new ticket.',
  aliases: ['newticket'],
  usage: 'new',
  userperms: [],
  botperms: [],
  run: async (client, message, args) => {

  if(!client.userTickets) client.userTickets = new Map()

        if(client.userTickets.has(message.author.id)) {
            return message.channel.send('<@' + message.author.id + '> you already have a ticket, please close your existing ticket first before opening a new one!').then(m => m.delete({timeout: 3000}));
        }
        
        message.guild.channels.create(`t-${client.userTickets.size + 1}`, {
            permissionOverwrites: [
                {
                    id: message.author.id,
                    allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                },
                {
                    id: "916785912267034674",
                    allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                },
                {
                    id: message.guild.roles.everyone,
                    deny: ['VIEW_CHANNEL'],
                },
            ],
            type: 'text',
        }).then(async channel => {
            channel.setParent('916778691672031293');
            client.userTickets.set(message.author.id, client.userTickets.size + 1);
            message.channel.send(`<@` + message.author.id + `>, you have successfully created a ticket! Please click on ${channel} to view your ticket.`).then(m => m.delete({timeout: 3000}));
            channel.send(`Hi <@` + message.author.id + `>, welcome to your ticket! Please be patient, we will be with you shortly.`);
            
            const logchannel = message.guild.channels.cache.find(channel => channel.name === 'test');
            
            if(logchannel) {
                logchannel.send(`Ticket-${client.userTickets.size} created. Click the following to veiw <#${channel.id}>`);
            }
        });
    }
}
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda